﻿#include "alterinfo.h"
#include "ui_alterinfo.h"
#include "facecollect.h"
#include <QSqlRecord>

alterInfo::alterInfo(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::alterInfo)
{
    ui->setupUi(this);
    this->setWindowFlag(Qt::FramelessWindowHint);

    model = new QSqlTableModel();//一定要在数据库db打开后才有效
    model->setTable("faceInfo");
    model->select();
    ui->tableView->setModel(model);

}

alterInfo::~alterInfo()
{
    delete ui;
}

void alterInfo::senddata(int ntimer)
{
    this->mtimer=ntimer;
}
//添加新员工

void alterInfo::on_pushButton_clicked()
{

    faceProject *win = new faceProject;
    win->show();

    this->close();
}
//删除
void alterInfo::on_deletbt_clicked()
{
    int row = ui->tableView->currentIndex().row();//获取当前所选的行
    if(row < 0)return ;
    model->removeRow(row);
    model->submitAll();
}
//查询
void alterInfo::on_pushButton_3_clicked()
{
    model->select();
}
//修改
void alterInfo::on_alterbt_clicked()
{
    int row = ui->tableView->currentIndex().row();//获取当前所选的行
    if(row < 0)return ;

    //获取数据
   QString name = ui->nameEdit->text();
   QSqlRecord record = model->record(row);

   record.setValue("name", name);

   //把数据放回模型中--QMessageBox提示
   model->setRecord(row, record);
   model->submitAll();
}

